package com.apexedu.eas.util;

import java.io.IOException;

import com.apexedu.eas.entity.test.Message;
import com.apexedu.eas.service.impl.ReceiveMsgImpl;
import com.apexedu.eas.vo.DxptVo;
import com.apexedu.framework.util.ConfigUtil;
import com.linkage.netmsg.NetMsgclient;
import com.linkage.netmsg.server.ReceiveMsg;

public class DXPTUtil {
	public static DxptVo dxptVo = null;
	public static NetMsgclient netMsgclient = new NetMsgclient();
	public static ReceiveMsgImpl receiveMsgImpl ;
	public static Boolean isLogin=false;

	public static Object sendMsg(Message message) throws IOException {
		if(isLogin){
			//登录了就可以发送短信
			System.out.println("上线状态，准备发送短信");
			String result=netMsgclient.sendMsg(netMsgclient, 0, message.getSjh(), message.getNr(), 1);
			return result;
		}else{
			if (dxptVo == null) {
				dxptVo = new DxptVo();
				dxptVo.setIpAddress(ConfigUtil.getString("dxptIpAddress"));
				dxptVo.setPort(Integer.valueOf(ConfigUtil.getString("dxptPort")));
				dxptVo.setUserName(ConfigUtil.getString("dxptUserName"));
				dxptVo.setPassword(ConfigUtil.getString("dxptPassword"));
				netMsgclient = netMsgclient.initParameters(dxptVo.getIpAddress(), dxptVo.getPort(),dxptVo.getUserName(),
						dxptVo.getPassword(), receiveMsgImpl);
				try {
					isLogin=netMsgclient.anthenMsg(netMsgclient);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(isLogin)
				return sendMsg(message);
			return null;
		}
	}
}
